package com.liwei.controller.advice;

import com.liwei.dto.ResultDTO;
import com.liwei.exception.CRUDException;
import com.liwei.exception.LoginException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class MyControllerAdvice {
    @ExceptionHandler(LoginException.class)
    public ResultDTO login(LoginException e){
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setResult(resultDTO.ERROR);
        resultDTO.setMess(e.getMessage());
        return resultDTO;
    }
    @ExceptionHandler(CRUDException.class)
    public ResultDTO crud(CRUDException e){
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setResult(resultDTO.ERROR);
        resultDTO.setMess(e.getMessage());
        return resultDTO;
    }
}
